package com.sky.mapper;

import com.sky.entity.DailyUserCount;
import com.sky.entity.User;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;

@Mapper
public interface UserMapper {
    /**
     * 根据openid查询用户
     * @param openid
     * @return
     */
    @Select("select * from user where openid = #{openid}")
    User findUserByOpenId(String openid);

    /**
     * 插入新用户
     * @param user
     */
    void insert(User user);

    /**
     * 根据userId查找
     * @param userId
     * @return
     */
    @Select("select * from user where id = #{userId}")
    User getById(Long userId);

    @Select("SELECT DATE(create_time) AS date, COUNT(*) AS count FROM user " +
            "WHERE create_time >= #{startDateTime} AND create_time < #{endDateTime} " +
            "GROUP BY DATE(create_time)")
    List<DailyUserCount> getDailyUserCounts(LocalDateTime startDateTime, LocalDateTime endDateTime);
}
